import React, { useState, useReducer } from 'react';
import './index.css';

const reducer = (state, action) => {
  if (action === '+') {
    return state + 1;
  }
  if (action === '-') {
    return state - 1;
  }
};

function Reducer() {
  // const [count, setCount] = useState(0);
  const [count, dispatch] = useReducer(reducer, 2);

  return (
    <div>
      Count: {count}
      <br />
      <button onClick={() => dispatch('-')}>-</button>
      <button onClick={() => dispatch('+')}>+</button>
      {/* <button onClick={() => setCount(count - 1)}>-</button> */}
      {/* <button onClick={() => setCount(count + 1)}>+</button> */}
    </div>
  );
}

export default Reducer;
